package com.health.service.Impl;

import cn.hutool.log.Log;
import com.health.context.BaseContext;
import com.health.dto.PatientDTO;
import com.health.entity.Patient;
import com.health.mapper.PatientMapper;
import com.health.service.PatientService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class PatientServiceImpl implements PatientService {

    @Autowired
    private PatientMapper patientMapper;

    // 就诊人列表
    @Override
    public List<Patient> getAll() {
        Long currentId = BaseContext.getCurrentId();
        List<Patient> byId = patientMapper.getById(currentId);
        return byId;
    }

    // 删除就诊人
    @Override
    public void delete(Integer id) {
        patientMapper.delete(id);
    }

    // 获取就诊人信息
    @Override
    public Patient select(Long id) {
        Patient patient = patientMapper.select(id);
        return patient;
    }

    // 添加就诊人
    @Override
    public void save(PatientDTO dto,Integer patientId) {
        dto.setUserId(BaseContext.getCurrentId());
        log.info("修改/添加 dto {}, patient  {}" ,dto.toString(),patientId);
        if (patientId != null) {
            dto.setId(patientId);
            patientMapper.modify(dto);
        }else {
            patientMapper.save(dto);
        }
    }

    @Override
    public List<Patient> getByUserIdAz() {
        List<Patient> byPatientId = patientMapper.getByUserIdAz(BaseContext.getCurrentId());
        return byPatientId;
    }
}
